package cn.tedu;

import cn.tedu.service.SomeService;
import cn.tedu.service.impl.SomeServiceImpl;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Date;


public class Mytest {
    @Test
    public void test01(){
        SomeService someService=new SomeServiceImpl();
        someService.dosome();
    }

    /*spring创建对象的时间：在创建spring的容器时，会同时创建配置文件中的所有对象。
    * */
    @Test
    public void test02(){
        String config="beans.xml";
        ApplicationContext ac=new ClassPathXmlApplicationContext(config);
        SomeService somoService = (SomeService) ac.getBean("someService");
        somoService.dosome();
    }

    /*获取spring容器中定义的java对象的信息*/
    @Test
    public void test03(){
        String config="beans.xml";
        ApplicationContext ac=new ClassPathXmlApplicationContext(config);
        //获取容器中定义对象的数量
        int number = ac.getBeanDefinitionCount();
        System.out.println("容器中定义对象的数量为："+number);
        //容器中定义对象的名字id
        String[] names = ac.getBeanDefinitionNames();
        for (String name : names) {
            System.out.println(name);
        }
    }


    /*创建一个非自定义的对象*/
    @Test
    public void test04(){
        String config="beans.xml";
        ApplicationContext ac=new ClassPathXmlApplicationContext(config);
        Date mydate = (Date) ac.getBean("mydate");
        System.out.println("date:"+mydate);
    }
}
